//云开发实现支付功能
const cloud = require('wx-server-sdk')
cloud.init()

//1、引入依赖
const tenpay = require('tenpay');

//2、配置支付参数
const config = {
  appid: 'wx7bf7cd461e4d056f', //appid已改
  mchid: '1601006678',//微信商户号已改
  partnerKey: '990cc389432e4f57afb4e181babf87aa',//微信支付安全密钥已改
  // pfx: require('fs').readFileSync('证书文件路径'), 退款时候的配置
  notify_url: 'http://baidu.com',
  spbill_create_ip: '127.0.0.1'
};

exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()

  let {
    orderid,
    money,
    notice
  } = event;

  //3、初始化
  const api = tenpay.init(config);

  //4、获取支付参数
  let result = await 
  api.getPayParams({
    out_trade_no: orderid, //订单号要唯一
    body: notice,
    total_fee: money, //订单金额(分)
    openid: wxContext.OPENID
  });
  return result
}